$(function () {
    queryWareHouse();
})
function checkPurchase(a) {
    let purchaseid = $(a).val();
    $.ajax({
        url:"/inboundManage/queryPurchaseById",
        type:"post",
        data:{"purchaseid":purchaseid},
        dataType:"json",
        success:function (r) {
            console.log(r)
            let str1 = "";
            let str = 0;
            if (r.rkid==null){
                str1 = "该采购单未入库";
                str = 1;
            }else {
                str1 = "采购单已入库";
                str = 2;
            }
            $(a).siblings("i").html("<span class='"+str+"'>"+str1+"</span>");
            let st = "";
            if (r.checkstatus==="未审核"){
                st = "1";
            }
            else if (r.checkstatus==="审核中"){
                st = "2";
            }else if (r.checkstatus==="审核通过"){
                st = "3";
            }else if (r.checkstatus==="审核未通过"){
                st = "4";
            }
            $(".checkstatus").html("<input type='hidden' name='"+st+"'>");
            $(".cgstatus").html("<input type='hidden' class='"+r.cgstatus+"'>");
        }
    })
}


function queryWareHouse() {
    $.ajax({
        url:"/inboundManage/queryAllWareHouse",
        type:"post",
        dataType: "json",
        success:function (r) {
            console.log(r);
            let str = "<option>请选择</option>";
            for (var i = 0; i < r.length; i++) {
                str += "<option>"+r[i].warehousename+"</option>"
            }
            $(".dfselect").html(str);
        }
    })
}

function addInbound(a) {
    let purchaseid = $(a).parents().siblings("li").eq(0).children(".dfinput").val();
    let wasehousename = $(a).parents().siblings("li").eq(1).children(".dfselect").val();
    let inboundTime = $(a).parents().siblings("li").eq(2).children("input").val();
    let username = $(a).parents().siblings("li").eq(3).children("input").val();
    let instatus = $(".cgstatus>input").attr("class");

    let checkstatus = $(".checkstatus>input").attr("name");
    let isExist = $(a).parents().siblings("li").eq(0).children("i").children("span").attr("class");


    if (checkstatus==="3"&&isExist==="1"&&wasehousename!="请选择"&&inboundTime!=null){
        $.ajax({
            url:"/inboundManage/inbound",
            type:"post",
            data:{"purchaseid":purchaseid,"wasehousename":wasehousename,"inboundTime":inboundTime,"username":username,"instatus":instatus},
            dataType:"json",
            success:function (r) {
                if (r===1){
                    alert("!!!")
                    location.reload();
                }
            }

        })
    }


}